package cn.ex.ymcc.util;

import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author: ZeWangmu
 * @Date: 2022/07/19/23:45
 * @Description: 获取ip的工具类
 */
public class GetIpUtil {

    /**
     * 获取ip地址的方法
     * @return
     */
    public static String getIp() {
        RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
        HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
        return request.getRemoteAddr();//获取IP地址
    }

}
